package gptma.bo.aop;

import java.lang.reflect.Method;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

import org.slf4j.Logger;

/**
 * 
 * @author xcl
 */
@Interceptor
@Logged
public class LoggingInterceptor {

	@Inject
	private Logger log;

	@AroundInvoke
	public Object logMethodCall(InvocationContext invocationContext)
			throws Exception {
		Method method = invocationContext.getMethod();
		String className = method.getDeclaringClass().getName();
		String methodName = method.getName();
		Object[] params = invocationContext.getParameters();

		log.debug("{}.{} > Begin({})", new Object[] { className, methodName,
				params });

		Object ret = invocationContext.proceed();

		log.debug("{}.{} > End({})",
				new Object[] { className, methodName, ret });

		return ret;
	}
}
